<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>欢迎使用联合防卫系统</title>
<script type="text/javascript" src="/static/js/root.js"></script>
<script src="/static/js/vue.js"></script>
<script src="/static/js/jquery-3.3.1.min.js"></script>
    <!-- 引入样式 -->
    <link rel="stylesheet" type="text/css" href="/static/css/index.css"/>
    <!-- 引入组件库 -->
    <script src="/static/js/element.js"></script>
</head>
<body>
<div id="app">
    <template>
        设备
        <el-button type="primary">地图设置</el-button>

        <el-button type="primary" @click="toDevice()">设备列表</el-button>


    </template>
</div>
<script type="text/javascript">
var app = new Vue({
    el: '#app',
    data(){
        return{
            message: 'Hello Vue!',
            tableDataDevice: [],
            tableDataUsers: []
        }

    },
    mounted :function () {
        this.init();
        console.log('load success...')

    },
    methods :{
        toDevice(){
            window.location.href = "/hub/v1/device";
        },
        init: function(){
        	console.log('call init method.')
        },
        getDeviceList:function(){
            var _this = this;
            $.ajax({
                type: "POST",
                url: root+"/device/getDeviceList",
                data: {},
                success: function(data){
                    _this.tableDataDevice =data.object;
                }
            });
        },

        getDeviceUsersList:function(){
            var _this = this;
            $.ajax({
                type: "POST",
                url: root+"/deviceUsers/getDeviceUsersList",
                data: {},
                success: function(data){
                    _this.tableDataUsers =data.object;
                }
            });
        },
        enabledChange:function(val){
            var _this = this;
            $.ajax({
                type: "POST",
                url: root+"/deviceUsers/enabledChange",
                data: {id:val.id,enabled:val.enabled},
                success: function(data){
                    debugger
                    if (data.object==1){
                        _this.message = "修改成功";
                        _this.getDeviceUsersList();
                    }else {
                        _this.message = "修改失败";
                    }
                }
            });
        },
        //踢掉
        disconnectDevice :function (val){
            var _this = this;
            this.$confirm('踢掉当前用户, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                $.ajax({
                    type: "POST",
                    url: root+"/device/disconnectDevice",
                    data: {id:val},
                    success: function(data){
                        if( data.state == "OK"){
                            _this.getDeviceList()
                        }
                    }
                });
                this.$message({
                    type: 'success',
                    message: '当前设备已被踢出!'
                });
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消'
                });
            });

        },
        refreshDD:function(){
        	var _this = this;
        	$.ajax({
                type: "GET",
                url: root+"/dataDictionary/refesh",
                data: {},
                success: function(data){
                	console.log(data);
                    _this.message = "刷新成功";
                }
            });
        },
        sendMQ:function(){
        	var _this = this;
        	$.ajax({
                type: "GET",
                url: root+"/sendMQ",
                data: {"message":"test!!"},
                success: function(data){
                	console.log(data);
                    _this.message = "发送成功";
                }
            });
        },
        pushData:function(val){
        	var _this = this;
        	$.ajax({
                type: "GET",
                url: root+"/device/pushData",
                data: {id:val,data:"/aaaa/111"},
                success: function(data){
                	console.log(data);
                    _this.message = data;
                }
            });
        },
        mongodbAddData:function(){
        	var _this = this;
        	$.ajax({
                type: "POST",
                url: root+"/mongodb/save",
                data: {"gender":"1","name":"zhangsan"},
                success: function(data){
                	console.log(data);
                    _this.message = data;
                }
            });
        },
        mongodbGetData:function(){
        	var _this = this;
        	$.ajax({
                type: "POST",
                url: root+"/mongodb/findById",
                data: {"id":"1619141750342"},
                success: function(data){
                	console.log(data);
                    _this.message = data;
                }
            });
        }
    }
});
</script>
<style acoped>


    /* 背景 */
    .login-container {
        position: absolute;
        width: 99%;
        height: 99%;
        background-image: url("/static/img/background.jpg");
    }

</style>
</body>
</html>
